package com.kaussoft.lolblog.action;

import org.apache.commons.lang.StringUtils;

import com.kaussoft.lolblog.vo.Account;

public class LoginAction extends AbstractAction{

	private static final long serialVersionUID = 1L;
	
	private String accountpass;
    private String accountname;
    
    public static final String sessionKey = "accountObj";
	
    public String execute() throws Exception {
    	if (!executeCheck()) {
            return INPUT;
        }

        Account account = getServiceManager().findAccountsByName(accountname, true);

        if (account == null) {
        	this.addActionError("没有此用户");
            return INPUT;
        } else if (!account.getAccountpass().equals(accountpass)) {
        	this.addActionError("密码错误");
            return INPUT;
        } else {
        	System.out.println(account.getWblogs().size());
        }
        this.set(sessionKey, account);

        return SUCCESS;
    }

    public String getAccountpass() {
        return accountpass;
    }

    public String getAccountname() {
        return accountname;
    }

	public void setAccountpass(String accountpass) {
        this.accountpass = accountpass;
    }
	
	public void setAccountname(String accountname) {
        this.accountname = accountname;
    }
	
	private boolean executeCheck() {
        if (StringUtils.isBlank(accountname) || StringUtils.isBlank(accountpass)) {
            return false;
        }
        return true;
    }
}